using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Openfree.Framework.DataAccess;

public partial class Portal_DocumentList : BaseUserControl
{
    private string htmlCode = string.Empty;
    //private string CategoryID  = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillGrid();
        }
    }

    public void FillGrid()
    {
        string cmdText = "select Subject, CreateDate, Author, CategoryID, DocumentID from T_Document {0} order by CreateDate desc";
        string CategoryID = Request["Category"];
        if (!string.IsNullOrEmpty(CategoryID))
        {
            CategoryID = CategoryID.Replace("'", "");
            cmdText = string.Format(cmdText, "where CategoryID like '" + CategoryID.Substring(0, CategoryID.Length - 2) + "%'");
        }
        else
        {
            cmdText = string.Format(cmdText, string.Empty);
        }
        string url = CategoryID + "&DocumentID=" + Request["DocumentID"];

        int currentPage = 0;
        Int32.TryParse(Request["page"], out currentPage);
        SqlSplitPage splitPage = new SqlSplitPage(base.Connection, cmdText);
        splitPage.PageSize = 10;
        htmlCode = splitPage.GetNavigation(currentPage, url, "../"+Request.AppRelativeCurrentExecutionFilePath.Replace("~/", ""));
        DataSet ds = splitPage.LoadDataSet(currentPage);
        gridView.ShowFooter = true;
        gridView.DataSource = ds.Tables[0];
        gridView.DataBind();
    }

    protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        try
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string subject = ((HyperLink)e.Row.Cells[0].Controls[0]).Text;
                if (subject.Length>25)
                {
                    ((HyperLink)e.Row.Cells[0].Controls[0]).Text = subject.Substring(0, 25) + "...";
                }
            }
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                e.Row.Cells.Clear();
                e.Row.Cells.Add(new TableCell());
                e.Row.Cells[0].ColumnSpan = 3;
                e.Row.Cells[0].Text = htmlCode;
            }
        }
        catch { }
    }
}
